<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">

        <ui:define name="content">
            <h:form>
                <p:commandButton rendered="#{loginBacking.addSalesLead}" action="#{salesLeadEntityController.prepareCreate}" ajax="false" value="Create New Sales Lead"/>
                <p:commandButton action="/entities/salesLeadEntity/Search.xhtml" ajax="false" value="Search for sales lead"/>

            </h:form>
            <br/>
            <p:panel header="Sales Leads" id="salesLeadList" toggleable="true">
                <h:form prependId="false">
                    <h:panelGroup id="messagePanel" layout="block">
                        <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
                    </h:panelGroup>
                    <h:outputText escape="true" value="#{bundle.ListSalesLeadEntityEmpty}" rendered="#{salesLeadEntityController.items.rowCount == 0}"/>
                    <h:panelGroup rendered="#{salesLeadEntityController.items.rowCount > 0}">
                        <p:dataTable value="#{salesLeadEntityController.items}" 
                                     var="item" style="table-layout:fixed"
                                     paginator="true" rows="10"  
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                     rowsPerPageTemplate="5,10,15">
                            <p:column filterBy="#{item.id}">
                                <f:facet name="header">
                                    <h:outputText value="#{bundle.ListSalesLeadEntityTitle_id}"/>
                                </f:facet>
                                <h:outputText value="#{item.id}"/>
                            </p:column>                      
                            <p:column filterBy="#{item.name}">
                                <f:facet name="header">
                                    <h:outputText value="#{bundle.ListSalesLeadEntityTitle_name}"/>
                                </f:facet>
                                <h:outputText value="#{item.name}"/>
                            </p:column>
                            <p:column filterBy="#{item.companyName}">
                                <f:facet name="header">
                                    <h:outputText value="#{bundle.ListSalesLeadEntityTitle_companyName}"/>
                                </f:facet>
                                <h:outputText value="#{item.companyName}"/>
                            </p:column>

                            <p:column filterBy="#{item.customerType}">
                                <f:facet name="header">
                                    <h:outputText value="Customer Type"/>
                                </f:facet>
                                <h:outputText value="#{item.customerType}"/>
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="#{bundle.ListSalesLeadEntityTitle_isArchived}"/>
                                </f:facet>
                                <h:outputText value= "Archived" rendered="#{item.archived==true}"/>
                                <h:outputText value= "Active" rendered="#{item.archived==false}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="&nbsp;"/>
                                </f:facet>
                                <p:commandButton image="ui-icon ui-icon-search" update="display" oncomplete="salesLeadDialog.show()" rendered="#{loginBacking.viewAllSalesLead}">
                                    <f:setPropertyActionListener value="#{item}"  
                                                                 target="#{salesLeadEntityController.salesLead}" /> 
                                </p:commandButton>
                            </p:column>
                            <p:column rendered="#{loginBacking.convertSalesLead or loginBacking.editSalesLead or loginBacking.deleteSalesLead}">  
                                <p:menuButton value="Options" >  
                                    <p:menuitem value=" Convert" ajax="false" icon="ui-icon ui-icon-arrowrefresh-1-w" 
                                                action="#{salesLeadEntityController.prepareConvert}" rendered="#{item.archived==false and loginBacking.convertSalesLead}"/>  
                                    <p:menuitem value=" Edit" ajax="false" icon="ui-icon ui-icon-disk" 
                                                action="#{salesLeadEntityController.prepareEdit}" rendered="#{loginBacking.editSalesLead}"/>
                                    <p:menuitem value=" Delete" ajax="false" rendered="#{item.archived==false and loginBacking.deleteSalesLead}" icon="ui-icon ui-icon-close"
                                                action="#{salesLeadEntityController.destroy}"/> 
                                    <p:menuitem value=" Activate" ajax="false" rendered="#{item.archived==true and loginBacking.deleteSalesLead}" icon="ui-icon ui-icon-close"
                                                action="#{salesLeadEntityController.activate}"/> 
                                </p:menuButton>    
                            </p:column>
                        </p:dataTable>
                        <p:dialog header="Sales Lead Detail" widgetVar="salesLeadDialog" resizable="false"  
                                  width="325" showEffect="explode" hideEffect="explode">  

                            <h:panelGrid id="display" columns="2" cellpadding="4">  
                                <h:outputText value="#{bundle.ListSalesLeadEntityTitle_id}"/>
                                <h:outputText value="#{salesLeadEntityController.salesLead.id}"/>
                                <h:outputText value="#{bundle.ListSalesLeadEntityTitle_title}"/>
                                <h:outputText value="#{salesLeadEntityController.salesLead.title}"/>
                                <h:outputText value="User Name: "/>
                                <h:outputText value="#{salesLeadEntityController.salesLead.name}"/>

                                <h:outputText value="First Name: "/>
                                <h:outputText value="#{salesLeadEntityController.salesLead.firstName}"/>

                                <h:outputText value="Last Name: "/>
                                <h:outputText value="#{salesLeadEntityController.salesLead.lastName}"/>

                                <h:outputText value="Company Name: "/>
                                <h:outputText value="#{salesLeadEntityController.salesLead.companyName}"/>

                                <h:outputText value="Job Title: "/>
                                <h:outputText value="#{salesLeadEntityController.salesLead.jobTitle}"/>

                                <h:outputText value="Contact Number: "/>
                                <h:outputText value="#{salesLeadEntityController.salesLead.contact.contactNumber}"/>

                                <h:outputText value="Contact Email: "/>
                                <h:outputText value="#{salesLeadEntityController.salesLead.contact.email}"/>

                                <h:outputText value="Customer Type"/>
                                <h:outputText value="#{salesLeadEntityController.salesLead.customerType}"/>

                                <h:outputText value="Created Date: "/>
                                <h:outputText value="#{salesLeadEntityController.salesLead.createdAt}">
                                    <f:convertDateTime pattern="MM/dd/yyyy" />
                                </h:outputText>

                                <h:outputText value="Created By: "/>
                                <h:outputText value="#{salesLeadEntityController.salesLead.createdBy.firstName}&nbsp;#{item.createdBy.lastName}"/>

                                <h:outputText value="Last Modified Date: "/>
                                <h:outputText value="#{salesLeadEntityController.salesLead.lastModifiedAt}">
                                    <f:convertDateTime pattern="MM/dd/yyyy" />
                                </h:outputText>

                                <h:outputText value="Last Modified By: "/>
                                <h:outputText value="#{salesLeadEntityController.salesLead.lastModifiedBy.firstName}"/>

                                <h:outputText value="Status: "/>
                                <h:outputText value= "Archived" rendered="#{salesLeadEntityController.salesLead.archived==true}"/>
                                <h:outputText value= "Active" rendered="#{salesLeadEntityController.salesLead.archived==false}"/>

                            </h:panelGrid>  
                        </p:dialog>
                    </h:panelGroup>
                    <br />
                </h:form>
            </p:panel>
        </ui:define>
    </ui:composition>

</html>
